/**
* @author AlbertDarren
* @contact 2563491540@qq.com
*/
#include <cstdio>
#include <algorithm>
using namespace std;

int main_1046()
{
    int N,M,exit1,exit2,dis,diff,sum=0;
    scanf("%d",&N);
    int exitDistance[N+1];
    for (int i=0; i<N;++i )
    {
        scanf("%d",&dis);
        exitDistance[i]=sum;
        sum+=dis;
    }
    scanf("%d",&M);
    for (int k=0;k<M ;++k )
    {
        scanf("%d%d",&exit1,&exit2);//assume exit2 > exit1
        if(exit1>exit2)
        {
            swap(exit1,exit2);
        }
        diff=exitDistance[exit2-1]-exitDistance[exit1-1];
        printf("%d\n",min(diff,sum-diff));
    }
	return 0;
}
